package com.visionet.waveletData.web.repository.plan.specs;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang3.StringUtils;
import org.springframework.data.jpa.domain.Specification;

import com.visionet.waveletData.web.entity.plan.PlayPlan;

public class PlayPlanSearchspecs {
	public static Specification<PlayPlan> searchTeamByCondition(final PlayPlan playPlan) {
		return new Specification<PlayPlan>(){

			@Override
			public Predicate toPredicate(Root<PlayPlan> root,
					CriteriaQuery<?> query, CriteriaBuilder cb) {
				List<Predicate> list = new ArrayList<Predicate>();
				
				if(playPlan.getId()!=null){
					list.add(cb.equal(root.<Long>get("id"), playPlan.getId()));
				}
				if(StringUtils.isNotEmpty(playPlan.getPlanName())) {
					list.add(cb.like(root.<String>get("planName"), "%"+playPlan.getPlanName()+"%"));
				}
				
				list.add(cb.equal(root.<String>get("is_deleted"), "0"));

				 Predicate[] predicate = new Predicate[list.size()];
		    	 return cb.and(list.toArray(predicate));
			}
		};
		
	}

}
